<?php

namespace app\command;

use app\common\model\NoticeSetting;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
use think\facade\Hook;
use think\facade\Log;

class DriverSendMes extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('dri');
        $this->setName('dri')->setDescription('配送员配送通知');
        // 设置参数
        
    }

    protected function execute(Input $input, Output $output)
    {
    	// 指令输出
        $output->writeln('处理时间：'.date('Y-m-d H:i:s'));
        try {
            $res = Db::name('order_mes')->where(['status' => 0])->select();
            if ($res) {
                foreach ($res as $item) {
                    $driver = Db::name('driver')->where(['site_id' => $item['site_id']])->field('id')->select();
                    Hook::listen('notice', [
                        'user_id' => $driver,
                        'order_id' => $item['order_id'],
                        'scene' => NoticeSetting::ORDER_PAY_NOTICE,
                    ]);
                }
            }


        }catch(Exception $e) {
            Log::write(date('Y-m-d H:i:s').'时间，报错：'.$e->getMessage());
        }
    }
}
